<?php
namespace app\admin\controller;

use think\facade\App;

class UserCenter extends Base {
    
    /**
     * @desc 用户列表
     */
    public function index() {
        $params['userName'] = input('userName', '', 'trim');
        $params['phone']    = input('phone', '', 'trim');
        $params['email']    = input('email', '', 'trim');

        $logic = App::model('UserCenter', 'logic');
        $data = $logic->index($params);
    
        $this->assign($data);
        return view();
    }
    
    /**
     * @desc 编辑配置
     */
    public function edit() {
        $params['action'] = input('action');
        $params['id']     = input('id');
        
        $logic = App::model('UserCenter', 'logic');
        $data = $logic->edit($params);

        $this->assign($data);
        return view();
    }
    
    /**
     * @desc 配置管理 (添加、编辑)
     */
    public function operateAjax() {
        $params['action'] = input('action');
        $params['id']     = input('id', 0);
        
        $params['userLevel']  = input('userLevel');
        
        $logic = model('UserCenter', 'logic');
        $data = [];
        try {
            $data = $logic->operateAjax($params);
        } catch (\Exception $e) {
            $logic->errorCode = EC_FAILURE;
            $logic->message = $e->getMessage();
        }
        return send_response($data, $logic->errorCode, $logic->message);
    }
}
